<template>
  <div id="rightAll">
    <div class="textSettingTitle text">文本内容</div>
    <div class="settingItem">
      <textarea
        name=""
        id="content"
        cols="30"
        rows="10"
        @keyup="keyup"
        v-text="currView.content"
      ></textarea>
    </div>
  </div>
</template>

<script>
export default {
  name: "textAttributionVue",
  props: ["views", "currView"],
  data() {
    return {
      styleObj: {
        content: "编辑文字",
      },
      // 不使用select定位选中的view了，直接把选中的view给currView，统一利用currView定位
      // selectId:"",
    };
  },
  methods: {
    changeElementStyle(element,styleObj) {
      let Currindex=this.views.length-1;
      // let Currindex=0;
      this.views.forEach((element,index) => {
          if(element.id===this.currView.id){ 
             Currindex=index;
          }
      });
      //      this.views.forEach((element,index) => {
      //     if(element.id===this.selectId){ 
      //        Currindex=index;
      //        console.log(Currindex,"index");
      //     }
      // });
    //   if (element.id != id) return;
      for (const key in styleObj) {
        if (Object.hasOwnProperty.call(styleObj, key)) {
           element[Currindex].content = styleObj[key];
        //   this.views[Currindex].content = styleObj[key];
        }
      }
    },
    keyup(e){
      console.log(e.target.value,"text");
      this.styleObj.content=e.target.value;
      this.changeElementStyle(this.views,this.styleObj);
    },
    // receiveSelectId(selectId){
    //   this.selectId=selectId;
    // }
  },
  updated() {
    // console.log(this.currView,"updata");
    // let Currindex = this.views.forEach((element, index) => {
    //   if (element.id === this.currView.id) {
    //     return index;
    //   }
    // });
    // this.changeElementStyle(this.views,this.styleObj);
  },
  watch:{

  },
  mounted(){
    // this.$bus.$on("receiveSelectId",this.receiveSelectId)
  }
};
</script>

<style>
#content {
  width: 99%;
  height: 480px;
  left: 0%;
}
</style>